package com.oop.example.processing;

import com.oop.example.work.esport.Esp2PortuTockenMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Карта токенов.
 * @author -
 */
public abstract class TockenMap {

    public static String columnAlias = "a.EntryType";

    /**
     * Возвращает все токены, которые может содержать статья.
     *
     * @return
     */
    public abstract Map<Integer, String> getFullTockenMap();
    private List<Integer> included = new ArrayList<Integer>();

    public void addTocken(int id) {
        if (!included.contains(id)) {
            included.add(id);
        }
    }

    public boolean contains(int id) {
        return included.contains(id);
    }

    public String getFilterMask() {
        String result = "";
        for (Integer id : getFullTockenMap().keySet()) {
            result += "t" + id + ":" + (included.contains(id) ? "1" : "0") + "#";
        }
        return result;
    }

    public String creatQueryMask(boolean invert, Integer... ids) {
        String result = "";
        for (Integer id : ids) {
            result += columnAlias + " LIKE '%t" + id + ":" + (invert ? "0" : "1") + "%' and ";
        }
        result = result.substring(0, result.length() - " and".length());
        return result;
    }

    public static void main(String[] args) {
        TockenMap map = new Esp2PortuTockenMap();
        System.out.println(map.creatQueryMask(false, 1, 2, 3));
    }
}
